from django.contrib import admin
from .models import ActivityCategory, Activity, ActivityRegistration, ActivityComment, ActivityRating, ActivityImage


@admin.register(ActivityCategory)
class ActivityCategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'is_default', 'created_at']
    list_filter = ['is_default', 'created_at']
    search_fields = ['name']


@admin.register(Activity)
class ActivityAdmin(admin.ModelAdmin):
    list_display = ['title', 'creator', 'category', 'status', 'start_time', 'current_participants', 'max_participants', 'created_at']
    list_filter = ['status', 'category', 'created_at']
    search_fields = ['title', 'description', 'creator__username']
    date_hierarchy = 'start_time'
    
    actions = ['approve_activities', 'reject_activities']
    
    def approve_activities(self, request, queryset):
        queryset.update(status='approved')
        self.message_user(request, f'已批准 {queryset.count()} 个活动')
    approve_activities.short_description = '批准选中的活动'
    
    def reject_activities(self, request, queryset):
        queryset.update(status='rejected')
        self.message_user(request, f'已拒绝 {queryset.count()} 个活动')
    reject_activities.short_description = '拒绝选中的活动'


@admin.register(ActivityRegistration)
class ActivityRegistrationAdmin(admin.ModelAdmin):
    list_display = ['activity', 'user', 'status', 'is_checked_in', 'created_at']
    list_filter = ['status', 'is_checked_in', 'created_at']
    search_fields = ['activity__title', 'user__username']


@admin.register(ActivityComment)
class ActivityCommentAdmin(admin.ModelAdmin):
    list_display = ['activity', 'user', 'content', 'likes_count', 'created_at']
    list_filter = ['created_at']
    search_fields = ['activity__title', 'user__username', 'content']


@admin.register(ActivityRating)
class ActivityRatingAdmin(admin.ModelAdmin):
    list_display = ['activity', 'user', 'score', 'created_at']
    list_filter = ['score', 'created_at']
    search_fields = ['activity__title', 'user__username']


@admin.register(ActivityImage)
class ActivityImageAdmin(admin.ModelAdmin):
    list_display = ['activity', 'user', 'description', 'created_at']
    list_filter = ['created_at']
    search_fields = ['activity__title', 'user__username']
